//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#if _MSC_VER > 1000
#pragma once
#endif

#ifndef __REQUEST_H__
#define __REQUEST_H__

#include "protocol.h"
#include <aura.h>

// add some data to be sent along with the request
inline static void add_request_data(void *req_ptr, const void *ptr, unsigned int size)
{
    struct central_request_info * const info = (struct central_request_info *)req_ptr;
    if (size) {
        info->request_data[info->request_data_count].ptr = (void*)ptr;
        info->request_data[info->request_data_count++].size = size;
    }
}

// set the pointer and max size for the reply var data
inline static void add_reply_data(void *req_ptr, const void *ptr, unsigned int size)
{
    struct central_request_info *info = (struct central_request_info *)req_ptr;
    if (size) {
        info->reply_data[info->reply_data_count].ptr = (void*)ptr;
        info->reply_data[info->reply_data_count++].size = size;
    }
}

EXTERN ECode central_call(Aura_ChannelId channelId, PVoid req_ptr, ECode * pResult);

// macros for server requests

#define SERVER_START_REQ(type) \
    do { \
        struct central_request_info info; \
        struct type##_request* req = &info.u.request.type##_request; \
        struct type##_reply* reply = &info.u.reply.type##_reply; \
        req->__header.reqNum = REQ_##type; \
        info.reply_data_count = 0; \
        info.request_data_count = 0; \
        (void)reply; \
        do

#define SERVER_END_REQ \
        while (0); \
    } while (0)

#endif /*__REQUEST_H__*/
